package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Behavior;
import com.ruoyi.system.service.IBehaviorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行为设定Controller
 * 
 * @author 不丢
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/system/behavior")
public class BehaviorController extends BaseController
{
    @Autowired
    private IBehaviorService behaviorService;

    /**
     * 查询行为设定列表
     */
    @PreAuthorize("@ss.hasPermi('system:behavior:list')")
    @GetMapping("/list")
    public TableDataInfo list(Behavior behavior)
    {
        startPage();
        List<Behavior> list = behaviorService.selectBehaviorList(behavior);
        return getDataTable(list);
    }

    /**
     * 导出行为设定列表
     */
    @PreAuthorize("@ss.hasPermi('system:behavior:export')")
    @Log(title = "行为设定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Behavior behavior)
    {
        List<Behavior> list = behaviorService.selectBehaviorList(behavior);
        ExcelUtil<Behavior> util = new ExcelUtil<Behavior>(Behavior.class);
        util.exportExcel(response, list, "行为设定数据");
    }

    /**
     * 获取行为设定详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:behavior:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(behaviorService.selectBehaviorById(id));
    }

    /**
     * 新增行为设定
     */
    @PreAuthorize("@ss.hasPermi('system:behavior:add')")
    @Log(title = "行为设定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Behavior behavior)
    {
        return toAjax(behaviorService.insertBehavior(behavior));
    }

    /**
     * 修改行为设定
     */
    @PreAuthorize("@ss.hasPermi('system:behavior:edit')")
    @Log(title = "行为设定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Behavior behavior)
    {
        return toAjax(behaviorService.updateBehavior(behavior));
    }

    /**
     * 删除行为设定
     */
    @PreAuthorize("@ss.hasPermi('system:behavior:remove')")
    @Log(title = "行为设定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(behaviorService.deleteBehaviorByIds(ids));
    }
}
